package bb;

/**
 * Created with IntelliJ IDEA.
 * User: Nacer
 * Date: 18/03/14
 * Time: 10:15
 * To change this template use File | Settings | File Templates.
 */
public class Bb {
    Node Solution;
    int nbNode;
    int nbSolution;
    int nbUnfeasible;

    public Bb() {
        Solution = null;
        nbNode = 0;
        nbSolution = 0;
        nbUnfeasible = 0;
    }
    public void addNode() { nbNode++; }
    public void addSolution() { nbSolution++; }
    public void addUnfeasible() { nbUnfeasible++; }

    public boolean testRecherche(Node n) {
        if ( n.isSolution()) {
            addSolution();
            if ( Solution==null || n.isBetter(Solution) ) Solution=n;
            return false;
        }
        addNode();
        return Solution==null || n.isBetter(Solution);
    }
    public String toString() {
        String s=new String("-------Branch and Bound-------\n");
        if ( Solution==null ) {
            s+="Pas de solution";
        } else
            s+=Solution.toString();
        s+="\n";
        s+="# Noeud      :"+nbNode+"\n";
        s+="# Solution       :"+nbSolution+"\n";
        s+="# Impossible:"+nbUnfeasible+"\n";

        return s;
    }


}

